﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using _619BJP.Database.Product;
using _619BJP.Models;
using System.Data;

namespace _619BJP.Web.Controllers
{
    public class ProductController : Controller
    {
        //
        // GET: /Product/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ProductIndex()
        {
            return View();
        }

        /// <summary>
        /// 最受关注产品
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetHotProducts(int count)
        {
            productDB productDB = new productDB();
            DataSet ds = productDB.GetProductListOrderByView(count);
            return ds;
        }

        /// <summary>
        /// 产品类别
        /// </summary>
        /// <returns></returns>
        public DataSet GetProductCategory()
        {
            productDB productDB = new productDB();
            DataSet ds = productDB.GetProductCategory();
            return ds;
        }

        /// <summary>
        /// 最受关注（按浏览数排序）
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetProductListOrderByView(int count)
        {
            productDB productDB = new productDB();
            DataSet ds = productDB.GetProductListOrderByView(count);
            return ds;
        }
            
        /// <summary>
        /// 产品详细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult ProductDetails(int id)
        {
            productDB productDB = new productDB();
            ProductModel productModel = productDB.productDetail(id);

            ViewData.Model = productModel;
            ViewData["Title"] = productModel.product_name;
            return View();
        }

        /// <summary>
        /// 产品对比
        /// </summary>
        /// <returns></returns>
        public DataSet GetProductsCompare(int product_id,int cate_id,int count)
        {
            productDB productDB = new productDB();
            DataSet ds = productDB.GetProductsForCompare(product_id,cate_id, count);
            return ds;
        }

        /// <summary>
        /// 产品推荐（按照类别）
        /// </summary>
        /// <returns></returns>
        public DataSet GetLikeProducts(int cate_id, int count)
        {
            productDB productDB = new productDB();
            DataSet ds = productDB.GetProductsByCategory(cate_id, count);
            return ds;
        } 

        /// <summary>
        /// 某类别下的产品列表
        /// </summary>
        /// <returns></returns>
        public ActionResult ProductList(int id)
        {
            productDB productDB = new productDB();
            DataSet ds = productDB.GetProductsByCategory(id, 0);

            ProductCategoryModel pc = productDB.GetProductsCategory(id);
            ViewData.Model = ds;
            ViewData["cate_id"] = pc.category_id;
            ViewData["cate_name"] = pc.category_name;
            return View();
        }

        /// <summary>
        /// 某类别下的产品列表
        /// </summary>
        /// <returns></returns>
        public DataSet GetProductList(int id, int count)
        {
            productDB productDB = new productDB();
            DataSet ds = productDB.GetProductsByCategory(id, count);
            return ds;
        } 

        /// <summary>
        /// 产品对比
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult ProductComparison(string id)
        {
            productDB productDB = new productDB();
            DataSet ds = productDB.GetProductsForCompareDetail(id);
            ViewData.Model = ds;
            return View();
        }

        /// <summary>
        /// 产品类别，根据所拥有的产品数倒序排列
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetCategoryOrderbyProductCount(int count)
        {
            productDB productDB = new productDB();
            DataSet ds = productDB.GetCategoryOrderbyProductCount(count);
            return ds;
        }
    }
}
